package com.itheima.demo;

import java.util.ArrayList;
import java.util.Objects;
import java.util.stream.Stream;

public class Demo03 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        list.add(new Student("卢本伟",23));
        list.add(new Student("马飞",24));
        list.add(new Student("卢本伟",23));
        list.add(new Student("uu",23));
        ArrayList<Student> list2 = new ArrayList<>();
        list2.add(new Student("abab",10));
        list.stream().limit(1).forEach(student -> System.out.println(student));
        System.out.println("=======================================");

        list.stream().skip(1).forEach(student -> System.out.println(student));
        System.out.println("=======================================");

        Stream.concat(list.stream(),list2.stream()).forEach(student -> System.out.println(student));
        System.out.println("=======================================");
        list.stream().distinct().forEach(student -> System.out.println(student));


    }
}
class Student{
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age &&
                Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}